# import requests
# response = requests.post(url="http://ihrm-test.itheima.net/api/sys/login",
#                             headers={"Content-Type":"application/json"},
#                          json={"mobile":"13800000002","password":"123456"})
# token = "Bearer " + response.json().get("data")
# print("获取的令牌为: ",token)
#
# response = requests.get(url="http://ihrm-test.itheima.net/api/company/department",
#                         headers={"Authorization":token})
# print("组织架构列表为: ",response.json())
# response = requests.post(url="http://ihrm-test.itheima.net/api/company/department",
#                          headers={"Content-Type":"application/json","Authorization":token},
#                          json={"name": "测试开发部","code": "9527"})
# print("添加部门结果为: ",response.json())
# emp_id = response.json().get("data").get("id")
# response = requests.get(url="http://ihrm-test.itheima.net/api/company/department"+"/"+emp_id,
#                         headers={"Authorization":token})
# print("查询部门结果为: ",response.json())
# response = requests.put(url="http://ihrm-test.itheima.net/api/company/department"+"/"+emp_id,
#                         headers={"Content-Type":"application/json","Authorization":token},
#                         json={"name": "测试开发部27期","code": "1008"})
# print("修改部门后的结果为: ",response.json())
# response = requests.delete(url="http://ihrm-test.itheima.net/api/company/department"+"/"+emp_id,
#                            headers={"Authorization":token})
# print("删除部门后的结果为: ",response.json())
import requests

session = requests.Session()
response = session.post(url="http://ihrm-test.itheima.net/api/sys/login",
                        headers={"Content-Type": "application/json"},
                        json={"mobile": "13800000002", "password": "123456"})
# token = "Bearer " + response.json().get("data")
# print("获取的令牌为: ",token)
print("登陆结果为: ", response.json())

response = session.get(url="http://ihrm-test.itheima.net/api/company/department")
print("组织架构列表为: ", response.json())
response = session.post(url="http://ihrm-test.itheima.net/api/company/department",
                         headers={"Content-Type": "application/json"},
                         json={"name": "测试开发部", "code": "9527"})
print("添加部门结果为: ", response.json())
emp_id = response.json().get("data").get("id")
response = session.get(url="http://ihrm-test.itheima.net/api/company/department" + "/" + emp_id)
print("查询部门结果为: ", response.json())
response = session.put(url="http://ihrm-test.itheima.net/api/company/department" + "/" + emp_id,
                        headers={"Content-Type": "application/json"},
                        json={"name": "测试开发部27期", "code": "1008"})
print("修改部门后的结果为: ", response.json())
response = session.delete(url="http://ihrm-test.itheima.net/api/company/department" + "/" + emp_id)
print("删除部门后的结果为: ", response.json())
